package com.wnhz.work.jy.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.jy.R;
import com.wnhz.work.jy.bean.RankingBean;

import org.xutils.image.ImageOptions;
import org.xutils.x;

import java.util.List;

/**
 * Created by Administrator on 2016/10/18 0018.
 */
public class RankingAdapter extends BaseAdapter {
    private Context context;
    private List<RankingBean> rankList;
    ImageOptions options = new ImageOptions.Builder()
            //设置加载过程中的图片
            .setLoadingDrawableId(R.mipmap.ic_morentouxiang)
            //设置加载失败后的图片
            .setFailureDrawableId(R.mipmap.ic_morentouxiang)
            //设置使用缓存
            .setUseMemCache(true)
            //设置显示圆形图片
            .setCircular(true)
            //设置支持gif
            .setIgnoreGif(false)
            .build();

    public RankingAdapter(Context context, List<RankingBean> rankList) {
        this.context = context;
        this.rankList = rankList;
    }

    @Override
    public int getCount() {
        return rankList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        RankViewHolder viewHolder = new RankViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.ranking_item, null);
            viewHolder.iv_good = (ImageView) convertView.findViewById(R.id.iv_good);//业绩勋章
            viewHolder.tv_number_rank = (TextView) convertView.findViewById(R.id.tv_number_rank);//排名
            viewHolder.iv_head_ranking = (ImageView) convertView.findViewById(R.id.iv_head_ranking);//头像
            viewHolder.tv_name_ranking = (TextView) convertView.findViewById(R.id.tv_name_ranking);//名字
            viewHolder.tv_money_ranking = (TextView) convertView.findViewById(R.id.tv_money_ranking);//金额
            viewHolder.tv_address_ranking = (TextView) convertView.findViewById(R.id.tv_address_ranking);//分处地址

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (RankViewHolder) convertView.getTag();
        }

        if (position == 0) {
            viewHolder.iv_good.setVisibility(View.VISIBLE);
            viewHolder.iv_good.setImageResource(R.mipmap.ic_yejidiyi);
            viewHolder.tv_number_rank.setVisibility(View.GONE);
        } else if (position == 1) {
            viewHolder.iv_good.setVisibility(View.VISIBLE);
            viewHolder.iv_good.setImageResource(R.mipmap.ic_yejidier);
            viewHolder.tv_number_rank.setVisibility(View.GONE);
        } else if (position == 2) {
            viewHolder.iv_good.setVisibility(View.VISIBLE);
            viewHolder.iv_good.setImageResource(R.mipmap.ic_yejidisan);
            viewHolder.tv_number_rank.setVisibility(View.GONE);
        } else {
            viewHolder.iv_good.setVisibility(View.INVISIBLE);
            viewHolder.tv_number_rank.setVisibility(View.VISIBLE);
        }

        viewHolder.tv_number_rank.setText(rankList.get(position).getNum());
//        ImageLoader.getInstance().displayImage(rankList.get(position).getHead(), viewHolder.iv_head_ranking);
        viewHolder.tv_name_ranking.setText(rankList.get(position).getName());
        viewHolder.tv_money_ranking.setText("¥ " + rankList.get(position).getMoney());
        viewHolder.tv_address_ranking.setText(rankList.get(position).getAddress());

        x.image().bind(viewHolder.iv_head_ranking, rankList.get(position).getHead(), options);
        return convertView;
    }

    class RankViewHolder {
        ImageView iv_good;
        TextView tv_number_rank;
        ImageView iv_head_ranking;
        TextView tv_name_ranking;
        TextView tv_money_ranking;
        TextView tv_address_ranking;
    }
}
